package cn.ittaoli.movie.controller;

import cn.ittaoli.movie.model.Admin;
import cn.ittaoli.movie.model.Nav;
import cn.ittaoli.movie.service.AdminService;
import cn.ittaoli.movie.service.NavService;
import cn.ittaoli.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by lub_lenovo on 2017/11/2.
 */
@RequestMapping("/nav")
@Controller
public class NavController {

    @Autowired
    private NavService navService;

    @RequestMapping("/add")
    public String add(){
        return "/admin/nav_add";
    }

    @RequestMapping("/doAdd")
    @ResponseBody
    public Integer doAdd(String navStr){
        Nav nav= JsonUtils.jsonToPojo(navStr,Nav.class);
        Integer res=navService.add(nav);
        return res;
    }

    @RequestMapping("/list")
    public String list(Model model){
        List<Nav> navs=navService.getList();
        model.addAttribute("navs",navs);
        return "/admin/nav_list";
    }
}
